package com.qfedu.scode.util;

/**
 * @program: StartCoding
 * @description:
 * @author: Feri(邢朋辉)
 * @create: 2021-01-05 17:48
 */
public class NameParseUtil {
    private static final String XHX="_";
    /**
     * 实现表名到类名的转换
     * @param name 要转换的表名*/
    public static String parseTableName(String name){
        if(name!=null && name.length()>0){
            if(name.length()==1){
                return name.toUpperCase();
            }else {
                if(name.contains(XHX)){
                    String[] arr=name.split(XHX);
                    if(arr!=null && arr.length>0){
                        StringBuffer buffer=new StringBuffer();
                        for(String s:arr){
                            if(s.matches("^[a-zA-Z]{1,}") && s.length()>2){
                                buffer.append(s.substring(0,1).toUpperCase()+s.substring(1).toLowerCase());
                            }
                        }
                        return buffer.toString();
                    }
                }else {
                    return name.substring(0,1).toUpperCase()+name.substring(1).toLowerCase();
                }
            }
        }
        return null;
    }
    /**
     * 将大驼峰式转换为小驼峰式命名
     * @param name 要转换的类名*/
    public static String parseParamName(String name){
        if(name!=null && name.length()>0) {
            return name.substring(0, 1).toLowerCase() + name.substring(1);
        }else {
            return null;
        }
    }
}